/*
 * StrahlentherapieROGHead.cc
 *
 *  Created on: Nov 14, 2010
 *      Author: holger
 */
 
#include "StrahlentherapieROGHead.hh"
#include "StrahlentherapieDummySD.hh"

#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4PVReplica.hh"
#include "G4ThreeVector.hh"
#include "G4PVPlacement.hh"

#include "G4Material.hh"
#include "G4NistManager.hh"

#include "G4Colour.hh"
#include "G4VisAttributes.hh"


StrahlentherapieROGHead::StrahlentherapieROGHead(G4String n, G4int nDiv) : G4VReadOutGeometry(n)
{
	this->nDiv = nDiv; // Unterteilung in nDiv*nDiv*nDiv Voxel
}

StrahlentherapieROGHead::~StrahlentherapieROGHead()
{}

G4VPhysicalVolume* StrahlentherapieROGHead::Build()
{
	G4NistManager* manager = G4NistManager::Instance();
	// den logischen Volumen muss ein Dummy-Material zugewiesen werden, wird aber nicht benutzt
	G4Material* dummy_air = manager->FindOrBuildMaterial("G4_AIR");

	// worldVolume
	G4double extent_x = 2.0*m;
	G4double extent_y = 2.0*m;
	G4double extent_z = 2.0*m;
	G4VSolid* ro_worldVolume_box = new G4Box("ro_worldVolume_box", extent_x, extent_y, extent_z);
	G4LogicalVolume* ro_worldVolume_log = new G4LogicalVolume(ro_worldVolume_box, dummy_air, "ro_worldVolume_log", 0, 0, 0);
	ro_worldVolume_log->SetVisAttributes(G4VisAttributes::Invisible);
	ro_worldVolume_phys = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.), ro_worldVolume_log, "ro_worldVolume_phys", 0, false, 0);
	
	// head	
	G4double head_extent_x = 20.*cm; // nur die halbe Kantenlänge der Box!!!
	G4double head_extent_y = 20.*cm;
	G4double head_extent_z = 20.*cm;
	G4double headAbsolutePosition_x = 0.*m;
	G4double headAbsolutePosition_y = 0.*m;
	G4double headAbsolutePosition_z = 1.*m;

	// sollte ein Würfel sein, ob es sein muss ist die Frage...
	G4VSolid* ro_head_box = new G4Box("ro_head_box", head_extent_x, head_extent_y, head_extent_z);
	G4LogicalVolume* ro_head_log = new G4LogicalVolume(ro_head_box, dummy_air, "ro_head_log", 0, 0, 0);
	ro_head_phys = new G4PVPlacement(0, G4ThreeVector(headAbsolutePosition_x, headAbsolutePosition_y, headAbsolutePosition_z), "ro_head_phys", ro_head_log, ro_worldVolume_phys, false, 0);
			
	// Unterteilung
	G4VSolid* ro_head_divZ_box = new G4Box("ro_head_divZ_box", head_extent_x, head_extent_y, head_extent_z/nDiv);
	G4LogicalVolume* ro_head_divZ_log = new G4LogicalVolume(ro_head_divZ_box, dummy_air, "ro_head_divZ_log", 0, 0, 0);
	G4VPhysicalVolume* ro_head_divZ_phys = new G4PVReplica("ro_head_divZ", ro_head_divZ_log, ro_head_phys, kZAxis, nDiv, head_extent_z/nDiv*2.);
	
	G4VSolid* ro_head_divY_box = new G4Box("ro_head_divY_box", head_extent_x, head_extent_y/nDiv, head_extent_z);
	G4LogicalVolume* ro_head_divY_log = new G4LogicalVolume(ro_head_divY_box, dummy_air, "ro_head_divY_log", 0, 0, 0);
	G4VPhysicalVolume* ro_head_divYZ_phys = new G4PVReplica("ro_head_divY", ro_head_divY_log, ro_head_divZ_phys, kYAxis, nDiv, head_extent_y/nDiv*2.);
	
	G4VSolid* ro_head_divX_box = new G4Box("ro_head_divX_box", head_extent_x/nDiv, head_extent_y, head_extent_z);
	G4LogicalVolume* ro_head_divX_log = new G4LogicalVolume(ro_head_divX_box, dummy_air, "ro_head_divX_log", 0, 0, 0);
	//G4VPhysicalVolume* ro_head_divXYZ_phys = 
	new G4PVReplica("ro_head_divX", ro_head_divX_log, ro_head_divYZ_phys, kXAxis, nDiv, head_extent_x/nDiv*2.);
	
	// es muss auch ein Dummy-SensitiveDetector zugewiesen werden, der ebenfalls nicht benutzt wird
	G4VSensitiveDetector * dummySD = new StrahlentherapieDummySD();
	ro_head_divX_log->SetSensitiveDetector(dummySD);
	
	return ro_worldVolume_phys;
}

